﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis;

namespace WMS_MAV.Controllers
{
    public class VonderController : Controller
    {
        private readonly IConfiguration _configuration;

        public VonderController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 供应商
        /// </summary>
        /// <returns></returns>
        public IActionResult VenderShow()
        {
            return View();
        }
        /// <summary>
        /// 供应商显示
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderShowDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Vendor/VendorShow";
            var response = await httpClientWrapper.PostAsync(url,model);
            return Json(response);
        }
        /// <summary>
        /// 供应商单删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderIsDelDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Vendor/VendorDelete";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 供应商下拉框类型
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderBangDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Vendor/VendorTypeBang";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 供应商添加
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderAddDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Vendor/VendorAdd";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 供应商反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderFanDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Vendor/VendorFan";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// 入库中的供应商反填
        /// </summary>
        /// <param name="token"></param>
        /// <param name="vendorId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderFanShow(string token,string vendorId)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Vendor/VendorShowFan";
            //string list = JsonConvert.SerializeObject(productId.productId);
            var list = "{\"vendorId\":" + vendorId + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 采购供应商类型显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetVendorNameShow(string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Vendor/VendorNameShow";
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 供应商修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        /// <summary>
        [HttpPost]
        public async Task<ActionResult> VenderupdateDo(string models, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Vendor/VendorUpdate";
            var response = await httpClientWrapper.PostAsync(url, models);
            return Json(response);
        }
        /// <summary>
        /// 供应商批删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> VenderIsdelAllDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Vendor/VendorIsdelAll";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
    }
}
